<?php
class Zendme_Models_CatItem extends Zend_Db_Table{
	protected $_name = 'product_category';
	protected $_primary = 'id';
	
	public function listItem($arrParam = null, $options = null){
		if($options == null){
			$ssFilter = $arrParam['ssFilter'];
			$db	= $this->getAdapter();
			$select = $db	->select()
							->from("product_category AS c",array('id','name','status','order','parents'))
							->order("order ASC")
							->where('status = 1');
			$result  = $db->fetchAll($select);
			$recursive = new Zendme_System_Recursive($result);
			$result = $recursive -> buildArray(0);
			return $result;	
		}
		if($options['task'] == 'search'){
			$db	= $this->getAdapter();
			$select = $db	->select()
							->from("product_category AS c",array('id','name'))
							->order("name ASC")
							->where("parents = 0");	
			$result  = $db->fetchPairs($select);
			return $result;	
		}
	}
	public function getItem($arrParam, $options = null){
			$select = $this->select()
						   ->where('id = ?',$arrParam['cid'],INTEGER);
			$result = $this->fetchAll($select) ->toArray();
		return $result;
	}
	public function getParent($arrParam, $options = null){
			$select1 = $this->select()
						   ->where('id = ?',$arrParam['cid'],INTEGER);						
			$result1 = $this->fetchAll($select1) ->toArray();	
			$parent = $result1[0][parents];
			if(!empty($parent)){
			
			
			$select = $this->select()
						   ->where('id = ?',$parent,INTEGER);
			$result = $this->fetchAll($select) ->toArray();	
		return $result;}
	}	
}